import 'package:flutter/material.dart';
import 'package:untitled5/friends_page.dart';

class Bar extends StatefulWidget {
  // const Bar({super.key});

  final void Function(String str) BarBack;
  Bar({required this.BarBack});

  @override
  State<Bar> createState() => _BarState();
}

// String getIndex(BuildContext context,Offset glo)

class _BarState extends State<Bar> {
  final List<Widget> words = [];
  Color bkColor = Color.fromRGBO(1, 1, 1, 0);
  Color textColor = Colors.black;
  @override
  void initState() {
    super.initState();

    for (int i = 0; i < words_index.length; i++) {
      words.add(Expanded(
          child: Text(
        words_index[i],
        style: TextStyle(fontSize: 10, color: textColor),
      )));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Positioned(
        top: MediaQuery.of(context).size.height / 8,
        width: 30,
        height: MediaQuery.of(context).size.height / 2,
        right: 0,
        child: GestureDetector(
          onVerticalDragUpdate: (DragUpdateDetails detauls) {
            RenderBox box = context.findRenderObject() as RenderBox;
            // print(box.globalToLocal(detauls.globalPosition));
            double y = box.globalToLocal(detauls.globalPosition).dy;
            // print(y);
            var itemHeight =
                MediaQuery.of(context).size.height / 2 / words_index.length;
            int index = (y ~/ itemHeight).clamp(0, words_index.length - 1);
            // String str = words_index[index];
            // print(str);
            widget.BarBack(words_index[index]);
          },
          child: Container(
            color: bkColor,
            child: Column(
              children: words,
            ),
          ),
        ));
  }
}
